#include "entity.h"
#include "images_diffuse.h"
#include "bullet.h"
#include "hitbox.h"
#include "tag.h"
#include "explosions.h"
#include "enemy.h"
#include "hitpoint.h"

declare_body(basic_spray, {
	float time;
	size_t period;
})

/* 20 different angles */
#define MULTIPLIER (6.28 / 20)
#define PERIOD 5

declare_tick(basic_spray, {
	if(self->period == 0) {
		make_enemy_bullet(
			get_animator_c(&sprite_basic_spray_bullet, 3, vxy(2.5f, 2.5f)),
			parent->position,
			vxy(cos(self->time * MULTIPLIER), sin(self->time * MULTIPLIER)),
			basic_spray_explosion
		);
		self->period = PERIOD;
		++self->time;
	}
	else --self->period;
})

declare_draw(basic_spray, { })

declare_head(basic_spray)

entity *make_basic_spray(vec location, int health) {
	entity *ent = ent_new();
	ent->position = vxy(location.x, 250);
	ent->tag = TAG_ENEMY;
	
	basic_spray *b = c_new(basic_spray);
	b->period = PERIOD;
	
	add_hitpoint_t(ent, vxy(-4, 13), 5, health);
	add_hitpoint_t(ent, vxy(4, 13), 4, health);
	add_hitpoint_t(ent, vxy(0, 12), 3, health);
	add_hitpoint_t(ent, vxy(0, 2), 2, health);
	add_hitpoint_t(ent, vxy(0, 6), 1, health);
	
	add_component(ent, get_animator_c(&sprite_basic_spray, PERIOD, vxy(5, 0)));
	add_component(ent, b);
	add_component(ent, target_loc(location));
	
	add_hitbox(ent, -5, 3, 10, 6);
	
	return ent;
}